﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWeb25.Default" %>
<%--<%@ Register Assembly="Web.Enhancements" Namespace="Web.Enhancements.Rest.WebControls" TagPrefix="rest" %>
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        div {padding-bottom:20px;}
    </style>
    <script>
//        var el = document.getElementById("s");

        //webRestExplorer.currentHttpMethod = 'POST';
        function myCallback(data) {
            alert("the data [" + data + "] is here.");
        }
        function myCallback2(data, par1, par2) {
            alert("the data [" + data + "] is here. As well as param1: " + par1 + ", " + "and param2: " + par2);
        }
        testCaller = {
            argCallbackTest: function () {
                TestWeb25.Components.InfoPreviewHandler.GetExtraInfo(2, this.callItNow, 'val1', 222);
            },
            callItNow: function (data, par1, par2) {
                alert("the data [" + data + "] is here. As well as param1: " + par1 + ", " + "and param2: " + par2);
            }
        };

        function jsonTest() {
            backendUserExperience.RetrieveEmployeeInfo2(235432, function (data) {
                alert(data.FName);
            });
        }
        window.setTimeout(function () {
            if (typeof (webRestExplorer) != "undefined")
                webRestExplorer.jsonSettings.autoParse = true;
        }, 500);
    </script>
    <script type="text/javascript">
        function runTest(url, formdata, callback) {
            var objHttp = new XMLHttpRequest();
            objHttp.onreadystatechange = function () {
                if (objHttp.readyState == 4 || objHttp.readyState == 'complete') {
                    var responseData = objHttp.responseText;
                    if (typeof(callback) != "undefined") {
                        callback(responseData);
                    }
                    else alert(responseData);
                }
            }
            objHttp.open("POST", url, true);
            objHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            objHttp.send(formdata);
        }
        function runTest2() {
            var dataIn = '{"UserId":235432,"LastName":"Jason","FirstName":"Mark","UserName":"Jasonman"}';
            runTest("http://localhost/TestWeb25/TestWeb25/Components/InfoPreviewHandler.rest?ResendDataWithExtra&userId=55&extraData=test", dataIn, function (dataOut) {
                if (dataIn != dataOut) alert("error: " + dataOut);
                else alert("OK");
            });
        }
        function runTest3() {
            var dataIn = '{"UserId":235432,"LastName":"Jason","FirstName":"Mark","UserName":"Jasonman"}';
            runTest("http://localhost/TestWeb25/TestWeb25/Components/InfoPreviewHandler.rest?ConvertResendData", dataIn, function (dataOut) {
                if ("Mark" != dataOut) alert("error: " + dataOut);
                else alert("OK");
            });
        }
        function runTest4() {
            var dataIn = '{"UserId":235432,"LastName":"Jason","FirstName":"Mark","UserName":"Jasonman"}';
            runTest("http://localhost/TestWeb25/TestWeb25/Components/InfoPreviewHandler.rest?AcceptBinaryData", dataIn, function (dataOut) {
                if ("77" != dataOut) alert("error: " + dataOut);
                else alert("OK");
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
<%--    <rest:RestClientManager ID="ScriptManager1" runat="server">
        <Scripts>
            <rest:ScriptReference Path="../Includes/AjaxCustomHandlers.js" />
            <rest:ScriptReference Path="Includes/rpt_JavaScript.js" />
        </Scripts>
        <Classes>
            <rest:ClassReference FullClassName="TestWeb25.Components.InfoPreviewHandler" Assembly="TestWeb25" />
        </Classes>
        <ErrorHandling ErrorMessageStartsWith="ErrorInfo" ClientDelegateName="MyHandler" />
    </rest:RestClientManager>
--%>    <div>
    hello!!!
    </div>
    <div>
        <asp:HyperLink ID="showExtraInfo" runat="server">Show Info with value 2</asp:HyperLink>
    </div>
    <div>
        <asp:HyperLink ID="showExtraInfo2" runat="server">Show Info with value 235432</asp:HyperLink>
    </div>
    <div>
        <asp:HyperLink ID="showSessionData" runat="server">Show SessionData</asp:HyperLink>
    </div>
    <div id="infoBlock">
    </div>

    <div>
        <a id="A1" href="javascript:TestWeb25.Components.InfoPreviewHandler.GetExtraInfo(2, myCallback);">Show Info with value 2 (with dynamic callback)</a>
    </div>
    <div>
        <a id="A2" href="javascript:TestWeb25.Components.InfoPreviewHandler.GetExtraInfo(2, myCallback2, 'val1', 222);">Show Info with value 2 (with dynamic callback and params)</a>
    </div>
    <div>
        <a id="A3" href="javascript:testCaller.argCallbackTest();">Show Info with value 2 (with dynamic callback and params - function pass in)</a>
    </div>

    <div>
        <img alt="My subject" src="backendUserExperience.rest?GetSubjectImage&subjectCode=MA" />
    </div>
    <div>
        <a title="Retrive My document" href="backendUserExperience.rest?ServeDocumentation&documentName=FunctionalSpecs_draft11_v9" target="_blank">Get my document</a>
    </div>
    <div>
        <a title="Retrive document using StaticFileResult" href="TestWeb25.Components.InfoPreviewHandler.rest?GetStaticFile&documentName=FunctionalSpecs_draft11_v9" target="_blank">Get document using StaticFileResult</a>
    </div>
    <div>
        <a title="Test 2" href="WebTest2.aspx">Go to Test2</a>
    </div>
    <div>This is a sample for URL call:&nbsp;
        <asp:Label ID="urlCallSample" runat="server"></asp:Label>
    </div>
    <div>
        <a title="Get help file" href="Web.Enhancements.Rest.Help.HelpProvider.rest?GetPdfHelp" target="_blank">Get help file.</a>
    </div>
    <div>
        <a title="Get JSON data" href="http://localhost/TestWeb25/TestWeb25/Components/UserExperienceHandler.rest?RetrieveEmployeeInfo&userId=235432" target="_blank">Get JSON data.</a>
    </div>
    <div>
        <a title="Get JSON data" href="http://localhost/TestWeb25/TestWeb25/Components/UserExperienceHandler.rest?RetrieveEmployeeInfo2&userId=235432" target="_blank">Get JSON data (with contract).</a>
    </div>
    <div>
        <a title="GetGreeting with templated result" href="http://localhost/TestWeb25/TestWeb25/Components/InfoPreviewHandler.rest?GetGreeting2&userName=lenny" target="_blank">GetGreeting with templated result.</a>
    </div>
    <div>
        <a title="Get JSON data with parsing" href="javascript:jsonTest();">Get JSON data (with parsing).</a>
    </div>
    <hr />
    <div>
        <a title="Run test 1 - simple" href="javascript:runTest('http://localhost/TestWeb25/TestWeb25/Components/InfoPreviewHandler.rest?GetExtraInfo', 'infoId=2');">Run POST test 1 - simple.</a>
    </div>
    <div>
        <a title="Run test 2" href="javascript:runTest2();">Run POST test 2.</a>
    </div>
    <div>
        <a title="Run test 3" href="javascript:runTest3();">Run POST test 3.</a>
    </div>
    <div>
        <a title="Run test 4 - binary" href="javascript:runTest4();">Run POST test 4 - binary.</a>
    </div>

    </form>
</body>
</html>
